
<?PHP
  header('Access-Control-Allow-Origin:*');

  $json = file_get_contents("content.json");

  $arr = json_decode($json, true); 

  $arr_content = $arr["data"];

  if ($_SERVER['REQUEST_METHOD'] != 'POST') { //判断是否为post请求，否：返回content.josn中的data
    $datas[] = array("code" => 200, "data" => $arr_content);
     echo json_encode($datas);
  } else { // 是post时，获取数据，添加到content.json的data中
    $get_data = array("name" => $_POST['username'], "content" => $_POST['content']);
    array_push($arr_content, $get_data);
    $arr["data"] = $arr_content;
    $json = json_encode($arr, true);
    file_put_contents("content.json", $json);
    echo 200;
  }

 